#{if _field.id!=null}

	<h2 id="crudShowTitle">Auspiciantes
	<img id="addAuspiciantesSubbase" src="/public/images/Add.png" alt="Add">
	<a href="@{Eventos.exportarAuspiciantes(_field.id)}" class="organizacion" ><img src="/public/images/download.png" alt="Edit" height="24px" width="24px"></a>
	</h2>
	<div class="auspiciantes">
		<table>		
			<thead>
				<tr>
					<th>Auspiciante</th>					
				</tr>
			</thead>
			#{if _field.auspiciantes!=null}
			#{list items:_field.auspiciantes.organizaciones, as:'auspiciante'}				
				<tr>
					<td>${auspiciante}</td>					
				</tr>
			#{/list}
			#{/if}
		</table>	
	</div>
	
	<div id="dialog-auspiciantes"  style="display: none" class="dialog-style">
		<h2 id="crudShowTitle">&{'crud.blank.title', 'Sub-base de Auspiciantes'}
		<input type="text" id="auspicianteSubbaseNameSearch" name="auspicianteSubbaseNameSearch">
		</h2>
		<div class="objectForm">
			<div class="crudField crud_text" id="auspicianteSubbaseDiv">
				<table id="auspicianteSubbaseTable">			
					#{list items:_subbases, as:'subbase'}				
						<tr><td><a href="@{Eventos.agregarAuspiciantes(_field.id, subbase.id)}" class="organizacion" >${subbase.nombre}</a></td></tr>
					#{/list}
				</table>
			</div>
		</div>	
	</div> 
	

<script type="text/javascript">
$().ready(function() {
	
	$( "#dialog-auspiciantes").dialog({
		autoOpen: false,
	    width: 550, 
	    maxWidth: 550,
	    minWidth: 430,
		height: 'auto',
		fluid: true, 
	    resizable: false,
	    dialogClass: "dialog-style",
	    open: function(event, ui){
	    },
	    close: function(event, ui){
	    	$( "#dialog-auspiciantes" ).dialog( "close" );
	    }
	});
	
	$("#auspicianteSubbaseNameSearch").keyup(function() {
		searchAuspiciantesSubbases();
	});
	$( "#addAuspiciantesSubbase" ).click(function() {
		$( "#dialog-auspiciantes" ).dialog( "open" );
		return false;
	});
})


function searchAuspiciantesSubbases(){
	$.get("/SubBases/search",  {
		nombre: $("#auspicianteSubbaseNameSearch").val()
	},function(data, id){
		if(data[0] != 'ERROR'){
			$("#auspicianteSubbaseTable").remove();
			var subbases = JSON.parse(data[1]);
			var i = 0;
			html = "<table id='auspicianteSubbaseTable'>";
			for(i = 0; i < subbases.length; i++) {
				html = html + 
				"<tr><td><a href='/Eventos/agregarAuspiciantes?evento=${_field.id}&auspiciante="+subbases[i].id+"' class='auspiciante' >"+ subbases[i].nombre + "</a></td></tr>";			
			}
			html = html + "</table>";
			$("#auspicianteSubbaseDiv").append(html);
			return false;
		} else {
			return false;
		}
		
	},'json');
}

</script>
#{/if}